import 'package:permission_handler/permission_handler.dart';

class PermissionUtil {
  static Future<bool> getPermissionStatus(Permission permission) async {
    //Permission permission = Permission.microphone;
    //granted 通过，denied 被拒绝，permanentlyDenied 拒绝且不在提示
    PermissionStatus status = await permission.status;
    if (status.isGranted) {
      return true;
    } else if (status.isDenied) {
      await requestPermission(permission);
    } else if (status.isPermanentlyDenied) {
      openAppSettings();
    } else if (status.isRestricted) {
      await requestPermission(permission);
    } else if(status.isLimited){
      await requestPermission(permission);
    } else {}
    return false;
  }

  ///申请权限
  static Future<void> requestPermission(Permission permission) async {
    PermissionStatus status = await permission.request();
    if (status.isPermanentlyDenied) {
      openAppSettings();
    }
  }
}